//
//  WJNetwrokManager.swift
//  WJWEIBO
//
//  Created by 文杰 许                       on 2018/7/4.
//  Copyright © 2018年 文杰 许                      . All rights reserved.
//

import UIKit
import Alamofire

/// swift 枚举支持任意数据类型
/// OC enum / switch 只支持整数
//enum WJHTTPMothod
//{
//    case GET
//    case POST
//}

class WJNetwrokManager:NSObject
{
    /// 网络请求单例
    static let sharedManager = WJNetwrokManager()
    
    var accessToken:String? = "2.00sAUduGDNQgHC8279f3032006VPdj"
    
    var uid:String? = "6333681974"
    
    
    public func requestAccessToken(url: URLConvertible, method: HTTPMethod = .get, parameters: Parameters?, completion:@escaping (_ json: DataResponse<Any>) -> Void)
    {
        guard let token = accessToken else
        {
            print("没有token，需要登录")
            return
        }
        
        var param = parameters
        if param == nil
        {
            param = Parameters()
        }
        param!["access_token"] = token
        
        request(url: url, parameters: param!, completion: completion)
    }
    
    public func request(url: URLConvertible, method: HTTPMethod = .get, parameters: Parameters?, completion:@escaping (_ json: DataResponse<Any>) -> Void)
    {
        Alamofire.request(url, method: method, parameters: parameters, encoding: URLEncoding.default, headers: nil).responseJSON(completionHandler: completion)
    }
}
